var Workport = Workport || {};

// @Path("/Stream")
Workport.StreamAPI = (function(){
	var root = WP_RESTFUL_URL + (WP_RESTFUL_URL.endsWith('/') ? '' : '/') + 'Stream';

    var urls = ["/Basic", "", "/{1}", "/ShareGeneric", "/Share", "/Update", "/UpdateGeneric", "/Filter", "/Entities", "/Comment",
                "/{1}/Comment", "/Like", "/{1}/Like", "/Bookmark", "/Subscribe", "/Delete", "/{1}/Export", "/Search", "/Community" , "/UserSubscribe",
                "/TaggingUser", "/Community/{1}" , "/Sticky", "/MailSubscribe", "/CommentGeneric","/sendmail","/AtMentionUsers"];

	function getUrl(/*index, replace1, replace2, ...*/) {
		var index, i, loops, r;
		loops = arguments.length;
		if (loops > 0) {
			index = arguments[0];
			r = root + urls[index];
			for (i = 1; i < loops; i++)
				r = r.replace("{"+i+"}", arguments[i]);
		}
		return r;
	}

	function sendRequest(method,url,callback,query,sync,data){
		if(method == 'get'){
			if(sync){
				return sfw.Http.syncGet(url,callback,query);
			} else {
				return sfw.Http.get(url,callback,query);
			}
		} else if(method == 'post'){
			if(sync){
				return sfw.Http.syncPost(url,callback,query,data);
			} else {
				return sfw.Http.post(url,callback,query,data);
			}
		} else if(method == 'put'){
			if(sync){
				return sfw.Http.syncPut(url,callback,query,data);
			} else {
				return sfw.Http.put(url,callback,query,data);
			}
		} 
	}
	
	return {
		// @GET		@Path("/Basic")
		// public StreamResponse GetSmartstream()
		getBasicStream:function(handler,request){
			return sendRequest('get',getUrl(0),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler,xhr)){
						handler(data,xhr);
					}
				}
			},{
				ps 		: 	request.pageSize,
				latest	:	request.latest,
				offset	:	request.offset ? request.offset : "",
				filter	:	request.filter ? request.filter : "0"
			},request.sync);
		},
		// @GET		@Path("/Search")
		// public StreamResponse searchStream()
		searchStream:function(handler,request){
            var domain = {
                key     :   request.key,
				ps 		: 	request.pageSize,
				offset	:	request.offset,
				tid		:	request.targetId
			};
            if(request.type){
                domain.type = request.type;
            }
            if(request.ispersonal){
                domain.ispersonal = request.ispersonal;
            }
			return sendRequest('get',getUrl(17),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},domain,request.sync);
		},
		// @GET		@Path("/")
		// public StreamDefaultResponse GetDefaultStream()
		getDefaultStream:function(handler,request){
			return sendRequest('get',getUrl(1),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler,xhr)){
						handler(data,xhr);
					}
				}
			},{
				ps 		: 	request.pageSize,
				latest	:	request.latest,
				offset	:	request.offset ? request.offset : "",
				filter	:	request.filter ? request.filter : "0",
				order   :   request.order
			},request.sync);
		},
		// @GET        @Path("/")
        // public StreamDefaultResponse GetDefaultStream()
        getConversationStream:function(handler,request){
        	var domain = {
        			tid         :     request.tid,
                    ispersonal    :    request.ispersonal
        	};
        	if(request.pageSize || request.offset || request.latest){
        		domain.ps        =     request.pageSize;
        		domain.latest    =    request.latest;
        		domain.offset    =    request.offset;
        	}
        	if(request.filter || request.order){
        		domain.filter = request.filter;
        		domain.order = request.order;
        	}
            return sendRequest('get',getUrl(1,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },domain,request.sync);
        },
		// @GET	@Path("/{NotificationID}")
		// public StreamDefaultResponse GetSmartNotification(@PathParam("NotificationID") String nofificationID)
		getStreamByNotify:function(handler,request){
			return sendRequest('get',getUrl(2,request.notificationId),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				ntype	:	request.type,
				tid		:	request.targetId,
				source  :   request.source
			},request.sync);
		},
		// @GET	@Path("/{NotificationID}")
		// public StreamDefaultResponse GetSmartNotification(@PathParam("NotificationID") String nofificationID)
		getStreamByTarget:function(handler,request){
			return sendRequest('get',getUrl(2,request.notificationId),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				tid			:	request.targetId,
				ispersonal	:	request.isPeronal
			},request.sync);
		},
		// @POST	@Path("/ShareGeneric")
		// public ShareResponse SharePost(ShareGenericPostRequest request)
		shareGeneric:function(handler,request){
			var domain = {};
			domain.TargetId = request.targetId;
			domain.EntityId = request.entityId;
			domain.NotificationText = request.text;
			domain.NotificationType = request.type;
			domain.Featured = request.featured ? request.featured :"''";
			domain.SubEntity = request.subEntity ? request.subEntity :"''";
			domain.Tags = request.tags ? request.tags :"''";
			domain.NotificationTitle = request.title ? request.title :"''";
			domain.hyperlinkURL = request.url ? request.url :"''";
			if(request.attachments){
				domain.AttachContents = [];
				for(var i=0;i<request.attachments.length;i++){
					domain.AttachContents[i] = {};
					domain.AttachContents[i].AttachmentName = request.attachments[i].name;
					domain.AttachContents[i].Attachmentbytes = request.attachments[i].content;
					domain.AttachContents[i].AttachmentType = request.attachments[i].type ? request.attachments[i].type : "''";
				}
			}
			if(request.images){
				domain.ImageContents = [];
				for(var i=0;i<request.images.length;i++){
					domain.ImageContents[i] = {};
					domain.ImageContents[i].AttachmentName = request.images[i].name;
					domain.ImageContents[i].Attachmentbytes = request.images[i].content;
					domain.ImageContents[i].AttachmentType = request.images[i].type ? request.images[i].type : "''";
				}
			}
			return sendRequest('post',getUrl(3),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},request,request.sync);
		},
		// @POST @Path("/Share")
		// public ShareResponse SharePost(SharePostRequest request)
		share:function(handler,request){
			return sendRequest('post',getUrl(4),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},request,request.sync/*{
				TargetId : request.targetId,
				EntityId : request.entityId,
				NotificationText : request.text,
				NotificationType : request.type,
				SubEntity : request.subEntity ? request.subEntity :"''",
				NotificationTitle : request.title ? request.title :"''",
				Tags : request.tags ? request.tags :"''"
			}*/);
		},
		// @PUT	@Path("/Update")
		// public BasicResponse PutUpdatePost(UpdateRequest request)
		putUpdate:function(handler,request){
			return sendRequest('put',getUrl(5),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				TargetId  : request.targetId,
				NotificationId  : request.Id,
				NotificationType  : request.type,
				NotificationText  : request.text,
				status  : request.status ? request.status : "''",
				AdditionalData  : request.additionalData ? request.additionalData : "''",
				Tags  : request.tags ? request.tags : "''",
				NotificationTitle  : request.title ? request.title : "''",
				BroadcastTo  : request.broadcast ? request.broadcast : "''"
			},request.sync);
		},
		// @PUT	@Path("/UpdateGeneric")
		// public BasicResponse PutUpdatePost(GenericUpdateRequest request)
		putGenericUpdate:function(handler,request){
			var domain = {};
			domain.TargetId  = request.targetId;
			domain.NotificationId  = request.id;
			domain.NotificationType  = request.type;
			domain.NotificationText  = request.text;
			domain.EntityId  = request.entityId;
			domain.hyperlinkURL  = request.url;
			domain.status  = request.status;
			domain.AdditionalData  = request.additionalData;
			domain.Tags  = request.tags;
			domain.NotificationTitle  = request.title;
			domain.BroadcastTo  = request.broadcast;
			domain.SubEntity  = request.subEntity;
			if(request.attachments){
				domain.AttachContents = [];
				for(var i=0;i<request.attachments.length;i++){
					domain.AttachContents[i] = {};
					domain.AttachContents[i].AttachmentName = request.attachments[i].AttachmentName;
					domain.AttachContents[i].Attachmentbytes = request.attachments[i].Attachmentbytes;
					if(request.attachments[i].AttachmentType){
						domain.AttachContents[i].AttachmentType = request.attachments[i].AttachmentType;
					}
				}
			}
			if(request.images){
				domain.ImageContents = [];
				for(var i=0;i<request.images.length;i++){
					domain.ImageContents[i] = {};
					domain.ImageContents[i].AttachmentName = request.images[i].AttachmentName;
					domain.ImageContents[i].Attachmentbytes = request.images[i].Attachmentbytes;
					if(request.images[i].AttachmentType){
						domain.ImageContents[i].AttachmentType = request.images[i].AttachmentType;
					}
				}
			}
			return sendRequest('put',getUrl(6),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},domain,request.sync);
		},
		// @GET	@Path("/Filter")
		// public List<Filter> FilterType()
		getFilter:function(handler,request){
			return sendRequest('get',getUrl(7),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},null,request ? request.sync : null);
		},
		// @GET	@Path("/Entities")
		// public List<Entity> GetEntityTypes()
		getEntities:function(handler,request){
			return sendRequest('get',getUrl(8),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},null,request ? request.sync : null);
		},
		// @POST	@Path("/Comment")
		// public BasicResponse PostComment(PostCommentRequest request)
		postComment:function(handler,request){
			console.log(request);
			/*return sendRequest('post',getUrl(9),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationId : request.id,
				NotificationType : request.type,
				CommentText : request.text,
				ToID : request.targetId
			},request.sync);*/
			return Workport.StreamAPI.postCommentGeneric(handler,{
                NotificationId : request.id,
                NotificationFromId : request.fromId,
                NotificationType : request.type,
                CommentText : request.text,
                ToID : request.targetId,
                AtMentionedUsers : request.AtMentionedUsers,
                sync : request.sync
            });
		},
		// @GET	@Path("/{NotificationID}/Comment")
		// public CommentResponse FetchComment(@PathParam("NotificationID") String nofificationID)
		getCommentByNotify:function(handler,request){
			return sendRequest('get',getUrl(10,request.id),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				tid		:	request.targetId,
				ps		:	request.pageSize,
				offset	:	request.offset,
				ntype	:	request.type
			},request.sync);
		},
		// @POST	@Path("/Like")
		// public BasicResponse PostLike(PutLikeRequest request)
		postLike:function(handler,request){
			return sendRequest('post',getUrl(11),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationId : request.id,
				NotificationType : request.type,
				NotificationFromID : request.fromId,
				TargetId : request.targetId,
				CommentedByID : request.commentedBy,
				CommentId : request.commentId
			},request.sync);
		},
		// @GET	@Path("/{NotificationID}/Like")
		// public List<LikeDetailResponse> GetLikedUsers(@PathParam("NotificationID") String nofificationID)
		getLikeByNotify:function(handler,request){
			return sendRequest('get',getUrl(12,request.targetId),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				ps	:	request.pageSize,
				pn	:	request.pageNumber
			},request.sync);
		},
		// @GET	@Path("/{NotificationID}/Like")
		// public List<LikeDetailResponse> GetLikedUsers(@PathParam("NotificationID") String nofificationID)
		getLikeDetail:function(handler,request){
			var url = "Stream/"+request.id+"/Like";
			return sendRequest('get',getUrl(12,request.targetId),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},null,request.sync);
		},
		// @POST	@Path("/Bookmark")
		// public BasicResponse Bookmark(BookmarkRequest request)
		bookmark:function(handler,request){
			return sendRequest('post',getUrl(13),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationId : request.id,
				NotificationType : request.type,
				ActionType : request.action,
				CommunityId : request.communityId
			},request.sync);
		},
		// @POST	@Path("/Subscribe")
		// public BasicResponse PostUpdateSubscription(SubscribeRequest request)
		subscribe:function(handler,request){
			return sendRequest('post',getUrl(14),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationID : request.id,
				ActionType : request.action,
				CommunityId : request.communityId
			},request.sync);
		},
		// @POST	@Path("/UserSubscribe")
		// public BasicResponse PostUpdateSubscription(SubscribeRequest request)
		userSubscribe:function(handler,request){
			return sendRequest('post',getUrl(19),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationID : request.id,
				ActionType : request.action,
				TarGetUserId : request.communityId
			},request.sync);
		},
		// @POST	@Path("/TaggingUser")
		// public BasicResponse TaggingUser(TaggingUserRequest request)
		taggingUser:function(handler,request){
			return sendRequest('post',getUrl(20),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				visitedUserId : request.userId,
				tagValue : request.tag
			},request.sync);
		},
		// @PUT	@Path("/Delete")
		// public BasicResponse Delete(DeleteRequest request)
		deleteStream:function(handler,request){
			return sendRequest('put',getUrl(15),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationId : request.id,
				NotificationType : request.type,
				TargetId : request.targetId
			},request.sync);
		},
		// @POST	@Path("/{notifyId}/Expert")
		// public BasicResponse UpdateExpertDetails(@PathParam("notifyId") String notifyId,ExpertRequest request)
		exportStream:function(handler,request){
			return sendRequest('post',getUrl(16,request.id),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationId : request.id,
				NotificationType : request.type,
				TargetId : request.targetId,
				ExpertsIds : request.exportId
			},request.sync);
		},		
		// add commont with attach,this will put UpdateGeneric and post Comment
		// @PUT		@Path("/UpdateGeneric")
		// @POST	@Path("/Comment")
		addCommentWithAttachOld:function(handler,request){
			var r = [];
			var domain = {};
			domain.TargetId  = request.targetId4Update;
			domain.NotificationId  = request.id;
			domain.NotificationType  = request.type;
			domain.NotificationText  = request.text4Update;
			domain.EntityId  = request.entityId;
			domain.hyperlinkURL  = request.url;
			domain.status  = request.status;
			domain.AdditionalData  = request.additionalData;
			domain.Tags  = request.tags;
			domain.NotificationTitle  = request.title;
			domain.BroadcastTo  = request.broadcast;
			domain.SubEntity  = request.subEntity;
			if(request.attachments){
				domain.AttachContents = [];

				for(var i=0;i<request.attachments.length;i++){
					domain.AttachContents[i] = {};
					domain.AttachContents[i].AttachmentName = request.attachments[i].AttachmentName;
					domain.AttachContents[i].Attachmentbytes = request.attachments[i].Attachmentbytes;
					if(request.attachments[i].AttachmentType){
						domain.AttachContents[i].AttachmentType = request.attachments[i].AttachmentType;
					}
				}
			}
			if(request.images){
				domain.ImageContents = [];
				for(var i=0;i<request.images.length;i++){
					domain.ImageContents[i] = {};
					domain.ImageContents[i].AttachmentName = request.images[i].AttachmentName;
					domain.ImageContents[i].Attachmentbytes = request.images[i].Attachmentbytes;
					if(request.images[i].AttachmentType){
						domain.ImageContents[i].AttachmentType = request.images[i].AttachmentType;
					}
				}
			}
			r[0] = {
				url 	:	getUrl(6),
				method 	:	"PUT",
				data	:	domain
			};
			r[1] = {
				url 	:	getUrl(9),
				method 	:	"POST",
				data	:	{
								NotificationId : request.id,
								NotificationType : request.type,
								CommentText : request.text4Comment,
								ToID : request.targetId4Comment
							}
			};
			sfw.Http.batch(r,handler);
		},
		// add commont with attach,this will put UpdateGeneric and post Comment
		// @PUT		@Path("/UpdateGeneric")
		// @POST	@Path("/Comment")
		addCommentWithAttach:function(handler,request){
			var domain = {};
            domain.NotificationId  = request.id;
            domain.NotificationType  = request.type;
            domain.NotificationFromId = request.fromId;
            domain.CommentText  = request.text4Comment;
            domain.ToID  = request.targetId4Comment;
			domain.AtMentionedUsers  = request.AtMentionedUsers;
            if(request.attachments){
                domain.AttachContents = [];
                for(var i=0;i<request.attachments.length;i++){
                    domain.AttachContents[i] = {};
                    domain.AttachContents[i].AttachmentName = request.attachments[i].AttachmentName;
                    domain.AttachContents[i].Attachmentbytes = request.attachments[i].Attachmentbytes;
                    if(request.attachments[i].AttachmentType){
                        domain.AttachContents[i].AttachmentType = request.attachments[i].AttachmentType;
                    }
                }
            }
            if(request.images){
                domain.ImageContents = [];
                for(var i=0;i<request.images.length;i++){
                    domain.ImageContents[i] = {};
                    domain.ImageContents[i].AttachmentName = request.images[i].AttachmentName;
                    domain.ImageContents[i].Attachmentbytes = request.images[i].Attachmentbytes;
                    if(request.images[i].AttachmentType){
                        domain.ImageContents[i].AttachmentType = request.images[i].AttachmentType;
                    }
                }
            }
            domain.sync = request.sync
            return Workport.StreamAPI.postCommentGeneric(handler,domain);
		},
		// get commont with like,this will get like and get comment
		// @GET		@Path("/{id}/Like")
		// @GET	@Path("/{id}/Comment")
		getCommentAndLike:function(handler,request){
			var r = [];
			r[0] = {
					url 	:	getUrl(10,request.id),//{1}/Comment
					method 	:	"GET",
					query	:	{
									tid		: request.targetId,
									ps		: request.pageSize4Comment,
									offset	: request.offset,
									ntype	: request.type
								}
			};
			r[1] = {
				url 	:	getUrl(12,request.id),//{1}/Like
				method 	:	"GET",
				query	:	{
								ps:request.pageSize4Like,
					            pn:request.PageNumber
							}
			};
			sfw.Http.batch(r,handler);
		},
		///////////////////////////////////////////////////////  For Community
		// @GET		@Path("/Community/{communityid}")
		// public CommunityNotificationResponse GetCommunityStream(@PathParam("communityid") String communityid)
		getCommunityDetail:function(handler,request){
			return sendRequest('get',getUrl(21,request.communityId),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(toViewModel(data), xhr);
					}
				}
			},{
				ps:request.pageSize,
				pp:request.pagePosition,
				order:request.order,
				filter:request.filter
			},request.sync);
			function toViewModel(data){
				if(data && data.Notifications){
					for(var i=0;i<data.Notifications.length;i++){
						data.Notifications[i].Attachments = data.Notifications[i].Attachment;
						data.Notifications[i].Images = data.Notifications[i].Image;
					}
				}
				return data;
			}
		},
		// @GET	@Path("/Community")
		// public BasicResponse GetCommunityStreamPreview()
		getCommunityPreview:function(handler,request){
			return sendRequest('get',getUrl(18),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(toViewModel(data), xhr);
					}
				}
			},{
				ps:request.pageSize,
				pp:request.pagePosition,
				order:request.order,
				ctype:request.type
			},request.sync);
			function toViewModel(data){
				var view;
                if(data){
                    view = {};
                    view.code = data.ResponseCode;
                    view.message = data.ResponseMessage;
                    view.data = [];
                    if(data!=undefined){
                        for(var i=0;data.NotificationPreviews && i < data.NotificationPreviews.length;i++){
                            view.data[i] = {};
                            view.data[i].id = data.NotificationPreviews[i].CommunityId;
                            view.data[i].icon = data.NotificationPreviews[i].CommunityImageUrl;
                            view.data[i].title = data.NotificationPreviews[i].CommunityName;
                            view.data[i].tip = 0;
                            view.data[i].tags = [];
                            for(var j=0;data.NotificationPreviews[i].CommunityTags && j<data.NotificationPreviews[i].CommunityTags.length;j++){
                                view.data[i].tags[j] = data.NotificationPreviews[i].CommunityTags[j];
                            }
                            view.data[i].notes = [];
                            for(var j=0;data.NotificationPreviews[i].ShortNotifications && j<data.NotificationPreviews[i].ShortNotifications.length;j++){
                                view.data[i].notes[j] = {};
                                view.data[i].notes[j].id = data.NotificationPreviews[i].ShortNotifications[j].NotificationId;
                                view.data[i].notes[j].fromId = data.NotificationPreviews[i].ShortNotifications[j].FromId;
                                view.data[i].notes[j].pic = data.NotificationPreviews[i].ShortNotifications[j].FromImageUrl;
                                view.data[i].notes[j].title = data.NotificationPreviews[i].ShortNotifications[j].NotificationTitle;
                                view.data[i].notes[j].desc = data.NotificationPreviews[i].ShortNotifications[j].NotificationText;
                                view.data[i].notes[j].passed = Workport.utils.calDays(data.NotificationPreviews[i].ShortNotifications[j].LastModifiedDate,data.NotificationPreviews[i].ServerDate);
                            }
                            if(i == data.NotificationPreviews.length - 1){
                                view.page = data.NotificationPreviews[i].PagePosition;
                            }
                        }
                    }
                }
				return view;
			}
		},
		// @POST		@Path("/Sticky")
		// public BasicResponse PutStickyDetails(StickyRequest request)
		setSticky:function(handler,request){
			return sendRequest('post',getUrl(22),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationID:request.notificationId,
				ActionType:request.action,
				CommunityId:request.communityId
			},request.sync);
		},
		// @POST		@Path("/MailSubscribe")
		// public BasicResponse MailSubscription(MailSubscriptionRequest request)
		subscriptionMail:function(handler,request){
			return sendRequest('post',getUrl(23),function(xhr,data){
				if (!sfw.Http.handleError(xhr, data)) {
					if(jQuery.isFunction(handler)){
						handler(data, xhr);
					}
				}
			},{
				NotificationID:request.notificationId,
				ActionType:request.action,
				NotificationType:request.notificationType,
				TargetID : request.targetId
			},request.sync);
		},
		// @POST        @Path("/CommentGeneric")
        // public CommentGenericResponse CommentGeneric()
        postCommentGeneric:function(handler,request){
            return sendRequest('post',getUrl(24),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data,data);
                    }
                }
            },request,request && request.sync);
        },
        // @POST        @Path("/sendmail")
        // public BasicResponse sendUserMail(SendMailRequest request)
        sendMail:function(handler,request){
            return sendRequest('post',getUrl(25,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },request,request && request.sync);
        },
        // @GET        @Path("/AtMentionUsers")
        // public MentionUserResponse GetAtMentionUsers()
        getMentionUsers:function(handler,request){
            return sendRequest('get',getUrl(26,this),function(xhr,data){
                if (!sfw.Http.handleError(xhr, data)) {
                    if(jQuery.isFunction(handler)){
                        handler(data, xhr);
                    }
                }
            },{
            	TargetID:request.targetID,
            	Ntype:request.type
			},request && request.sync);
        }
	}
})();
